<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是串口通信——串口格式化函数printf的移植的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV04-04-串口通信-03-串口格式化函数移植">
<meta property="og:url" content="https://sumumm.github.io/post/9f4500db.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是串口通信——串口格式化函数printf的移植的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20230729153948757.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240119004011983.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240116231150136.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240116233107762.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240119003227288.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240119003653270.png">
<meta property="article:published_time" content="2023-09-08T11:24:12.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.039Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="(ALPHA)LV04-裸机开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20230729153948757.png">


<link rel="canonical" href="https://sumumm.github.io/post/9f4500db.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/9f4500db.html","path":"post/9f4500db.html","title":"LV04-04-串口通信-03-串口格式化函数移植"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV04-04-串口通信-03-串口格式化函数移植 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E6%A6%82%E8%BF%B0"><span class="nav-text">一、概述</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81printf%E7%A7%BB%E6%A4%8D"><span class="nav-text">二、printf移植</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%BB%8Euboot%E7%A7%BB%E6%A4%8D"><span class="nav-text">1. 从uboot移植</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%87%AA%E5%B7%B1%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%EF%BC%9F"><span class="nav-text">2. 自己实现一个？</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%9F%BA%E7%A1%80%E5%B7%A5%E7%A8%8B%E7%BB%93%E6%9E%84"><span class="nav-text">2.1 基础工程结构</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-1-%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="nav-text">2.1.1 目录结构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-2-imx6ull-lds"><span class="nav-text">2.1.2 imx6ull.lds</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-3-main-c"><span class="nav-text">2.1.3 main.c</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-4-start-S"><span class="nav-text">2.1.4 start.S</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-5-uart-c"><span class="nav-text">2.1.5 uart.c</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-6-uart-h"><span class="nav-text">2.1.6 uart.h</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-7-Makefile"><span class="nav-text">2.1.7 Makefile</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E7%A7%BB%E6%A4%8Dprintf"><span class="nav-text">2.2 移植printf</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-raise%E5%87%BD%E6%95%B0"><span class="nav-text">2.2.1 raise函数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-%E4%BF%AE%E6%94%B9-Makefile"><span class="nav-text">2.2.2 修改 Makefile  </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-3-%E5%8F%98%E5%8F%82%E6%95%B0%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D"><span class="nav-text">2.2.3 变参数函数移植  </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-4-%E7%BC%96%E5%86%99-my-vprintf-fmt-ap"><span class="nav-text">2.2.4 编写 my_vprintf(fmt, ap)  </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-5-%E7%BC%96%E5%86%99-out-c%EF%BC%8C-outs-%E4%B8%8E-out-num-%E5%87%BD%E6%95%B0"><span class="nav-text">2.2.5 编写 out_c， outs 与 out_num 函数  </span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-6-%E6%B5%8B%E8%AF%95%E5%87%BD%E6%95%B0"><span class="nav-text">2.2.6 测试函数</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E7%A7%BB%E6%A4%8D%E5%90%8E%E7%9A%84%E5%B7%A5%E7%A8%8B%E7%BB%93%E6%9E%84"><span class="nav-text">2.3 移植后的工程结构</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-1-%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="nav-text">2.3.1 目录结构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-2-imx6ull-lds"><span class="nav-text">2.3.2 imx6ull.lds</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-3-main-c"><span class="nav-text">2.3.3 main.c</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-4-start-S"><span class="nav-text">2.3.4 start.S</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-5-uart-c"><span class="nav-text">2.3.5 uart.c</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-6-uart-h"><span class="nav-text">2.3.6 uart.h</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-7-Makefile"><span class="nav-text">2.3.7 Makefile</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-8-mp-printf-c"><span class="nav-text">2.3.8 mp_printf.c</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-9-my-printf-h"><span class="nav-text">2.3.9 my_printf.h</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E6%B5%8B%E8%AF%95%E6%95%88%E6%9E%9C"><span class="nav-text">2.4 测试效果</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-5-%E5%9C%B0%E5%9D%80%E6%89%93%E5%8D%B0"><span class="nav-text">2.5 地址打印</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/9f4500db.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV04-04-串口通信-03-串口格式化函数移植 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV04-04-串口通信-03-串口格式化函数移植
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-08 19:24:12" itemprop="dateCreated datePublished" datetime="2023-09-08T19:24:12+08:00">2023-09-08</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/" itemprop="url" rel="index"><span itemprop="name">02IMX6ULL平台</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV04-裸机开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6.3k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>23 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是串口通信——串口格式化函数printf的移植的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows版本</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu版本</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>      </tr>    <tr>        <td align="center">Linux开发板</td>        <td align="left">正点原子 i.MX6ULL Linux 阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">Win32DiskImager</td>        <td align="left">Win32DiskImager v1.0</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="5">官方网站</td>        <td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td>        <td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/" target="_blank">https://www.nxp.com.cn/ </a></td>        <td align="left">NXP官方网站</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxpic.org.cn/" target="_blank">https://www.nxpic.org.cn/</a></td><td align="left">NXP 官方社区</td>    </tr>    <tr>        <td align="left"><a href="https://u-boot.readthedocs.io/en/latest/" target="_blank">https://u-boot.readthedocs.io/en/latest/</a></td><td align="left">u-boot官网</td>    </tr>    <tr>        <td align="left"><a href="https://www.kernel.org/" target="_blank">https://www.kernel.org/</a></td><td align="left">linux内核官网</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="4">NXP</td>        <td align="left"><a href="https://github.com/nxp-imx" target="_blank">https://github.com/nxp-imx</a></td>        <td align="left">NXP imx开发资源GitHub组织，里边会有u-boot和linux内核的仓库</td>    </tr>    <tr>        <td align="left"><a href="https://elixir.bootlin.com/linux/latest/source" target="_blank">https://elixir.bootlin.com/linux/latest/source</a></td>        <td align="left">在线阅读linux kernel源码</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP linux内核仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP u-boot仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="center" rowspan="2">I.MX6ULL</td>        <td align="left"><a href="https://www.nxp.com.cn/docs/en/data-sheet/IMX6ULLIEC.pdf" target="_blank">i.MX 6ULL Applications Processors for Industrial Products</a></td>        <td align="left">I.MX6ULL 芯片手册（datasheet，可以在线查看）</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/webapp/Download?colCode=IMX6ULLRM&lang_cd=zh" target="_blank">i.MX 6ULL Applications ProcessorReference Manual</a></td>        <td align="left">I.MX6ULL 参考手册（下载后才能查看，需要登录NXP官网）</td>    </tr></table>
              </div>
            </details>

<h1 id="一、概述"><a href="#一、概述" class="headerlink" title="一、概述"></a><font size=3>一、概述</font></h1><p>上一节中，我们实现了 UART1 基本的数据收发功能，虽然可以用来调试程序，但是功能太单一了，只能输出字符。如果需要输出数字的时候就需要我们自己先将数字转换为字符，非常的不方便。学习 STM32 串口的时候我们都会将 printf 函数映射到串口上，这样就可以使用printf 函数来完成格式化输出了，使用非常方便。那 printf 这样的格式化函数能移植到 I.MX6U-ALPHA 开发板上吗？当然也可以啦。  </p>
<p>格式化函数说的是 printf、 sprintf 和 scanf 这样的函数，分为格式化输入和格式化输出两类函数。学习 C 语言的时候常常通过 printf 函数在屏幕上显示字符串，通过 scanf 函数从键盘获取输入。这样就有了输入和输出了，实现了最基本的人机交互。在 I.MX6U-ALPHA 开发板上也可以将 printf 和 scanf 映射到串口上，这样就可以使用 MobaXterm 作为开发板的终端，完成与开发板的交互。也可以使用 printf 和 sprintf 来实现各种各样的格式化字符串，方便我们后续的开发。</p>
<h1 id="二、printf移植"><a href="#二、printf移植" class="headerlink" title="二、printf移植"></a><font size=3>二、printf移植</font></h1><h2 id="1-从uboot移植"><a href="#1-从uboot移植" class="headerlink" title="1. 从uboot移植"></a><font size=3>1. 从uboot移植</font></h2><p>这里直接用了正点原子的资料，他为我们提供了一个stdio文件夹</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20230729153948757.png" alt="image-20230729153948757" style="zoom:50%;" />

<p>stdio 里面的文件其实是从 uboot 里面移植过来的。其实都是可以从 uboot 源码还有交叉编译工具链安装目录里面找出相应的文件，完成格式化函数的移植。这里要注意一点， stdio 中并没有实现完全版的格式化函数，比如 printf 函数并不支持浮点数，但是基本够我们使用了。  移植完成后，直接编译可能会报下边的警告：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">In file included from project/main.c:5:0:</span><br><span class="line">bsp/uart/bsp_uart.h:12:6: 警告： conflicting types for built-in function ‘putc’</span><br><span class="line"> void putc(unsigned char c);</span><br><span class="line">      ^</span><br><span class="line">bsp/uart/bsp_uart.h:13:6: 警告： conflicting types for built-in function ‘puts’</span><br><span class="line"> void puts(char *str);</span><br><span class="line">      ^</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>这个表示“putc”、“puts”这两个函数与内建函数冲突，在编译的时候加入选项“-fno-builtin”表示不使用内建函数就可以了。另外还需要添加在编译 C 文件的时候添加选项“-Wa,-mimplicit-it&#x3D;thumb”，否则的话会有如下类似的错误提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">thumb conditional instruction should be in IT block -- `addcs r5,r5,#65536    </span><br></pre></td></tr></table></figure>

<p>移植完成后，可以看gitee仓库：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-bare-demo/tree/master/02_UART/03_printf">02_UART&#x2F;03_printf · sumumm&#x2F;imx6ull-bare-demo - 码云 - 开源中国 (gitee.com)</a></p>
<h2 id="2-自己实现一个？"><a href="#2-自己实现一个？" class="headerlink" title="2. 自己实现一个？"></a><font size=3>2. 自己实现一个？</font></h2><p>自己实现的这个是参考的韦东山教程的逻辑开发教程，所以这里写一下基于的工程情况吧。可以看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-bare-demo/tree/master/02_UART/04_my_printf">02_UART&#x2F;04_my_printf · sumumm&#x2F;imx6ull-bare-demo - 码云 - 开源中国 (gitee.com)</a>。需要注意的是这里的printf后面的换行只能是<code>\n\r</code>，换成<code>\r\n</code>就会报以下问题：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240119004011983.png" alt="image-20240119004011983" style="zoom:40%;" />

<p>具体原因还不清楚，上面直接移植uboot中相关文件的版本倒是没问题，后面知道了再补充。</p>
<h3 id="2-1-基础工程结构"><a href="#2-1-基础工程结构" class="headerlink" title="2.1 基础工程结构"></a><font size=3>2.1 基础工程结构</font></h3><h4 id="2-1-1-目录结构"><a href="#2-1-1-目录结构" class="headerlink" title="2.1.1 目录结构"></a><font size=3>2.1.1 目录结构</font></h4><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240116231150136.png" alt="image-20240116231150136" style="zoom:50%;" />

<h4 id="2-1-2-imx6ull-lds"><a href="#2-1-2-imx6ull-lds" class="headerlink" title="2.1.2 imx6ull.lds"></a><font size=3>2.1.2 imx6ull.lds</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">SECTIONS &#123;</span><br><span class="line">    . = 0x80100000;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    .text      :</span><br><span class="line">    &#123;</span><br><span class="line">      *(.text)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    .rodata : &#123; *(.rodata) &#125;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    .data : &#123; *(.data) &#125;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    __bss_start = .;</span><br><span class="line">    .bss : &#123; *(.bss) *(.COMMON) &#125;</span><br><span class="line">    __bss_end = .;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-1-3-main-c"><a href="#2-1-3-main-c" class="headerlink" title="2.1.3 main.c"></a><font size=3>2.1.3 main.c</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;uart.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span>  <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">unsigned</span> <span class="type">char</span> cTestData ;       <span class="comment">/*用于测试发送的数据*/</span></span><br><span class="line"> 	Uart_Init()	 ;</span><br><span class="line"></span><br><span class="line">	PutStr(<span class="string">&quot;Hello, world!\n\r&quot;</span>);	<span class="comment">/*发送字符串*/</span></span><br><span class="line">	</span><br><span class="line">	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">	&#123;	</span><br><span class="line">		cTestData = GetChar() ;				<span class="comment">/*等待从串口获取数据*/</span></span><br><span class="line">		</span><br><span class="line">			<span class="keyword">if</span> (cTestData == <span class="string">&#x27;\r&#x27;</span>)  		<span class="comment">/*添加回到行首\r*/</span></span><br><span class="line">			&#123; </span><br><span class="line">				PutChar(<span class="string">&#x27;\n&#x27;</span>);</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			<span class="keyword">if</span> (cTestData == <span class="string">&#x27;\n&#x27;</span>)			<span class="comment">/*换行\n*/</span></span><br><span class="line">			&#123;</span><br><span class="line">				PutChar(<span class="string">&#x27;\r&#x27;</span>);</span><br><span class="line">			&#125;</span><br><span class="line">				</span><br><span class="line">		PutChar(cTestData)    ;				<span class="comment">/*从串口发送数据*/</span></span><br><span class="line">	&#125;</span><br><span class="line">					</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125; 			 		  						  					  				 </span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-1-4-start-S"><a href="#2-1-4-start-S" class="headerlink" title="2.1.4 start.S"></a><font size=3>2.1.4 start.S</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">.text</span><br><span class="line">.global  _start</span><br><span class="line">_start: 				</span><br><span class="line"></span><br><span class="line">	/* 设置栈 */</span><br><span class="line">	ldr  sp,=0x80200000</span><br><span class="line">	/* 清除bss段 */</span><br><span class="line">	bl clean_bss</span><br><span class="line">	/* 跳转到主函数 */</span><br><span class="line">	bl main</span><br><span class="line"></span><br><span class="line">halt:</span><br><span class="line">	b  halt </span><br><span class="line"></span><br><span class="line">clean_bss:</span><br><span class="line">	ldr r1, =__bss_start	// 将链接脚本变量__bss_start变量保存于r1</span><br><span class="line">	ldr r2, =__bss_end      // 将链接脚本变量__bss_end变量保存于r2</span><br><span class="line">	mov r3, #0</span><br><span class="line">clean:</span><br><span class="line">	strb r3, [r1]		// 将当前地址下的数据清零</span><br><span class="line">	add r1, r1, #1		// 将r1内存储的地址+1</span><br><span class="line">	cmp r1, r2		// 相等：清零操作结束；否则继续执行clean函数清零bss段</span><br><span class="line">	bne clean</span><br><span class="line">	</span><br><span class="line">	mov pc, lr</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-1-5-uart-c"><a href="#2-1-5-uart-c" class="headerlink" title="2.1.5 uart.c"></a><font size=3>2.1.5 uart.c</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;uart.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="type">static</span> <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA ;</span><br><span class="line"><span class="type">static</span> <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA	;</span><br><span class="line"><span class="type">static</span> <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *IOMUXC_UART1_RX_DATA_SELECT_INPUT ;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">Uart_Init</span><span class="params">(<span class="type">void</span>)</span>	 				</span><br><span class="line">&#123;</span><br><span class="line">	</span><br><span class="line">	IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA		= (<span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *)(<span class="number">0x20E0084</span>);</span><br><span class="line">	IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA		= (<span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *)(<span class="number">0x20E0088</span>);</span><br><span class="line">	IOMUXC_UART1_RX_DATA_SELECT_INPUT		= (<span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *)(<span class="number">0x20E0624</span>);</span><br><span class="line"></span><br><span class="line">	*IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA = <span class="number">0</span>;</span><br><span class="line">	*IOMUXC_UART1_RX_DATA_SELECT_INPUT = <span class="number">3</span>;</span><br><span class="line">	*IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">	UART1-&gt;UCR1 |= (<span class="number">1</span> &lt;&lt; <span class="number">0</span>) ;		<span class="comment">/*关闭当前串口*/</span> </span><br><span class="line">	</span><br><span class="line">	<span class="comment">/* </span></span><br><span class="line"><span class="comment">	 *  设置UART传输格式：</span></span><br><span class="line"><span class="comment">	 *  UART1中的UCR2寄存器关键bit如下</span></span><br><span class="line"><span class="comment">	 *  [14]:	1：忽略RTS引脚</span></span><br><span class="line"><span class="comment">	 *  [8] :	0: 关闭奇偶校验 默认为0，无需设置</span></span><br><span class="line"><span class="comment">	 *  [6] :	0: 停止位1位	    默认为0，无需设置</span></span><br><span class="line"><span class="comment">	 *  [5] :	1: 数据长度8位</span></span><br><span class="line"><span class="comment">	 *  [2] :	1: 发送数据使能</span></span><br><span class="line"><span class="comment">	 *  [1] :	1: 接收数据使能</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	</span><br><span class="line">	UART1-&gt;UCR2 |= (<span class="number">1</span>&lt;&lt;<span class="number">14</span>) |(<span class="number">1</span>&lt;&lt;<span class="number">5</span>) |(<span class="number">1</span>&lt;&lt;<span class="number">2</span>)|(<span class="number">1</span>&lt;&lt;<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 *  UART1中的UCR3寄存器关键bit如下</span></span><br><span class="line"><span class="comment">	 *  [2]:  1:根据官方文档表示，IM6ULL的UART用了这个MUXED模型，提示要设置	</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	</span><br><span class="line">	UART1-&gt;UCR3 |= (<span class="number">1</span>&lt;&lt;<span class="number">2</span>);</span><br><span class="line">	</span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * 设置波特率</span></span><br><span class="line"><span class="comment">	 * 根据芯片手册得知波特率计算公式:</span></span><br><span class="line"><span class="comment">	 * Baud Rate = Ref Freq / (16 * (UBMR + 1)/(UBIR+1))</span></span><br><span class="line"><span class="comment">	 * 当我们需要设置 115200的波特率</span></span><br><span class="line"><span class="comment">	 * UART1_UFCR [9:7]=101，表示不分频，得到当前UART参考频率Ref Freq ：80M ，</span></span><br><span class="line"><span class="comment">	 * 带入公式：115200 = 80000000 /(16*(UBMR + 1)/(UBIR+1))</span></span><br><span class="line"><span class="comment">	 * </span></span><br><span class="line"><span class="comment">	 * 选取一组满足上式的参数：UBMR、UBIR即可</span></span><br><span class="line"><span class="comment">	 *	</span></span><br><span class="line"><span class="comment">	 * UART1_UBIR    = 71</span></span><br><span class="line"><span class="comment">	 * UART1_UBMR = 3124  </span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	 </span><br><span class="line">    UART1-&gt;UFCR = <span class="number">5</span> &lt;&lt; <span class="number">7</span>;       <span class="comment">/* Uart的时钟clk：80MHz */</span></span><br><span class="line">    UART1-&gt;UBIR = <span class="number">71</span>;</span><br><span class="line">    UART1-&gt;UBMR = <span class="number">3124</span>;</span><br><span class="line"></span><br><span class="line">	UART1-&gt;UCR1 |= (<span class="number">1</span> &lt;&lt; <span class="number">0</span>);		<span class="comment">/*使能当前串口*/</span> </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">PutChar</span><span class="params">(<span class="type">int</span> c)</span>						</span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">while</span> (!((UART1-&gt;USR2) &amp; (<span class="number">1</span>&lt;&lt;<span class="number">3</span>))); <span class="comment">/*等待上个字节发送完毕*/</span></span><br><span class="line">	UART1-&gt;UTXD = (<span class="type">unsigned</span> <span class="type">char</span>)c;		</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">unsigned</span> <span class="type">char</span> <span class="title function_">GetChar</span><span class="params">(<span class="type">void</span>)</span>						</span><br><span class="line">&#123;	</span><br><span class="line">	<span class="keyword">while</span> (!(UART1-&gt;USR2 &amp; (<span class="number">1</span>&lt;&lt;<span class="number">0</span>)));  <span class="comment">/*等待接收数据*/</span></span><br><span class="line">	<span class="keyword">return</span> (<span class="type">unsigned</span> <span class="type">char</span>)UART1-&gt;URXD;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">PutStr</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *s)</span>				</span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">while</span> (*s)</span><br><span class="line">	&#123;</span><br><span class="line">		PutChar(*s);</span><br><span class="line">		s++;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-1-6-uart-h"><a href="#2-1-6-uart-h" class="headerlink" title="2.1.6 uart.h"></a><font size=3>2.1.6 uart.h</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifndef</span> _UART_H_</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> _UART_H_</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">/*UART1的寄存器的基地址*/</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> UART1_BASE          (0x2020000u)</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> UART1    ((UART_Type *)UART1_BASE)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*根据IMX6ULL芯片手册&lt;&lt;55.15 UART Memory Map/Register Definition&gt;&gt;的3608页，定义UART的结构体,*/</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> &#123;</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  URXD;               <span class="comment">/**&lt; UART Receiver Register, offset: 0x0 	           串口接收寄存器，偏移地址0x0     */</span></span><br><span class="line">  		   <span class="type">unsigned</span> <span class="type">char</span> RESERVED_0[<span class="number">60</span>];		</span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UTXD;               <span class="comment">/**&lt; UART Transmitter Register, offset: 0x40          串口发送寄存器，偏移地址0x40*/</span></span><br><span class="line">  		   <span class="type">unsigned</span> <span class="type">char</span> RESERVED_1[<span class="number">60</span>];		</span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR1;               <span class="comment">/**&lt; UART Control Register 1, offset: 0x80 	       串口控制寄存器1，偏移地址0x80*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR2;               <span class="comment">/**&lt; UART Control Register 2, offset: 0x84 	       串口控制寄存器2，偏移地址0x84*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR3;               <span class="comment">/**&lt; UART Control Register 3, offset: 0x88            串口控制寄存器3，偏移地址0x88*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR4;               <span class="comment">/**&lt; UART Control Register 4, offset: 0x8C            串口控制寄存器4，偏移地址0x8C*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UFCR;               <span class="comment">/**&lt; UART FIFO Control Register, offset: 0x90         串口FIFO控制寄存器，偏移地址0x90*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  USR1;               <span class="comment">/**&lt; UART Status Register 1, offset: 0x94             串口状态寄存器1，偏移地址0x94*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  USR2;               <span class="comment">/**&lt; UART Status Register 2, offset: 0x98             串口状态寄存器2，偏移地址0x98*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UESC;               <span class="comment">/**&lt; UART Escape Character Register, offset: 0x9C     串口转义字符寄存器，偏移地址0x9C*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UTIM;               <span class="comment">/**&lt; UART Escape Timer Register, offset: 0xA0         串口转义定时器寄存器 偏移地址0xA0*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UBIR;               <span class="comment">/**&lt; UART BRM Incremental Register, offset: 0xA4      串口二进制倍率增加寄存器 偏移地址0xA4*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UBMR;               <span class="comment">/**&lt; UART BRM Modulator Register, offset: 0xA8 	   串口二进制倍率调节寄存器 偏移地址0xA8*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UBRC;               <span class="comment">/**&lt; UART Baud Rate Count Register, offset: 0xAC      串口波特率计数寄存器 偏移地址0xAC*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  ONEMS;              <span class="comment">/**&lt; UART One Millisecond Register, offset: 0xB0      串口一毫秒寄存器 偏移地址0xB0*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UTS;                <span class="comment">/**&lt; UART Test Register, offset: 0xB4                 串口测试寄存器 偏移地址0xB4*/</span>		</span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UMCR;               <span class="comment">/**&lt; UART RS-485 Mode Control Register, offset: 0xB8  串口485模式控制寄存器 偏移地址0xB8*/</span></span><br><span class="line">&#125; UART_Type;</span><br><span class="line">		  			 		  						  					  				 	   		  	  	 	 </span><br><span class="line"><span class="type">void</span> <span class="title function_">Uart_Init</span><span class="params">(<span class="type">void</span>)</span>;		</span><br><span class="line"><span class="type">void</span> <span class="title function_">PutChar</span><span class="params">(<span class="type">int</span> c)</span>;</span><br><span class="line"></span><br><span class="line"> <span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-1-7-Makefile"><a href="#2-1-7-Makefile" class="headerlink" title="2.1.7 Makefile"></a><font size=3>2.1.7 Makefile</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">PREFIX=arm-linux-gnueabihf-</span><br><span class="line">CC=<span class="variable">$(PREFIX)</span>gcc</span><br><span class="line">LD=<span class="variable">$(PREFIX)</span>ld</span><br><span class="line">AR=<span class="variable">$(PREFIX)</span>ar</span><br><span class="line">OBJCOPY=<span class="variable">$(PREFIX)</span>objcopy</span><br><span class="line">OBJDUMP=<span class="variable">$(PREFIX)</span>objdump</span><br><span class="line"></span><br><span class="line">uart.img : start.S  uart.c main.c</span><br><span class="line">	<span class="variable">$(CC)</span> -nostdlib -g -c -o start.o start.S</span><br><span class="line">	<span class="variable">$(CC)</span> -nostdlib -g -c -o uart.o uart.c	</span><br><span class="line">	<span class="variable">$(CC)</span> -nostdlib -g -c -o main.o main.c	</span><br><span class="line">	</span><br><span class="line">	<span class="variable">$(LD)</span> -T imx6ull.lds -g start.o uart.o main.o -o uart.elf </span><br><span class="line">	</span><br><span class="line">	<span class="variable">$(OBJCOPY)</span> -O binary -S uart.elf  uart.bin</span><br><span class="line">	<span class="variable">$(OBJDUMP)</span> -D -m arm  uart.elf  &gt; uart.dis	</span><br><span class="line">	./tools/mkimage -n ./tools/imximage.cfg.cfgtmp -T imximage -e 0x80100000 -d uart.bin uart.imx</span><br><span class="line">	dd if=/dev/zero of=1k.bin bs=1024 count=1</span><br><span class="line">	cat 1k.bin uart.imx &gt; uart.img</span><br><span class="line"></span><br><span class="line"><span class="section">clean:</span></span><br><span class="line">	rm -f uart.dis  uart.bin uart.elf uart.imx uart.img *.o</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h3 id="2-2-移植printf"><a href="#2-2-移植printf" class="headerlink" title="2.2 移植printf"></a><font size=3>2.2 移植printf</font></h3><h4 id="2-2-1-raise函数"><a href="#2-2-1-raise函数" class="headerlink" title="2.2.1 raise函数"></a><font size=3>2.2.1 raise函数</font></h4><p>在 uart.c 中加入 raise 函数，用于防止编译失败。  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">raise</span><span class="params">(<span class="type">int</span> signum)</span><span class="comment">/* raise函数，防止编译报错 */</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2-2-2-修改-Makefile"><a href="#2-2-2-修改-Makefile" class="headerlink" title="2.2.2 修改 Makefile  "></a><font size=3>2.2.2 修改 Makefile  </font></h4><p>my_printf.c 中用到除法的求模运算，需要提供除法库。一般的交叉工具链里都提示有基本的数学运算，它们位于 libgcc.a 中。我们需要把 libgcc.a也链接进程序里，需要修改 Makefile。  </p>
<p>注意：链接指令中，每个“ -L”表示库在哪里，即它的目录；“ -l”表示哪个库，即库的名称， -lgcc 表示会链接“libgcc.a”库。  </p>
<p>对 Makefile 作如下修改：  </p>
<p>（1）增加<code>$(CC) -nostdlib -g -c -o my_printf.o my_printf.c  </code></p>
<p>（2）在<code>$(LD) -T imx6ull.lds -g start.o uart.o main.o my_printf.o -o my_printf.elf </code>后<br>添加<code>-lgcc – L&lt;libgcc.a 的路径&gt; </code>。</p>
<p>例如：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$(LD)</span> -T imx6ull.lds -g start.o uart.o main.o my_printf.o -o my_printf.elf -lgcc -L/home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_armlinux-gnueabihf/lib/gcc/arm-linux-gnueabihf/6.2.1</span><br></pre></td></tr></table></figure>

<h4 id="2-2-3-变参数函数移植"><a href="#2-2-3-变参数函数移植" class="headerlink" title="2.2.3 变参数函数移植  "></a><font size=3>2.2.3 变参数函数移植  </font></h4><p>函数参数列表包括了字符串（ format）和变参（…）组合而成， 在 vc6.0 的头文件 stdarg.h 中找到 typedef char * va_list：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">define</span> _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) &amp; ~(sizeof(int) - 1) )</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> va_start(ap,v) ( ap = (va_list)&amp;v + _INTSIZEOF(v) )</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> va_end(ap) ( ap = (va_list)0 )</span></span><br></pre></td></tr></table></figure>

<p>① _INTSIZEOF(n) 用于获取其中一个变参类型占用的空间长度。</p>
<p>② va_start(ap,v) 令 ap 指向第一个变参地址。</p>
<p>③ va_arg(ap,t) 取出一个变参，同时指针指向下一个变参。</p>
<p>④ va_end(ap) 将指针指向 NULL，防止野指针  。</p>
<p>我们移植以上的代码，编写一个属于自己的 printf。参考 int printf(const char *format, …)库函数，实现 my_printf。我们创建my_printf.c  ：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//reference :  int printf(const char *format, ...); </span></span><br><span class="line"><span class="type">int</span> <span class="title function_">printf</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *fmt, ...)</span> </span><br><span class="line">&#123;</span><br><span class="line">	va_list ap;</span><br><span class="line"></span><br><span class="line">	va_start(ap, fmt);</span><br><span class="line">	my_vprintf(fmt, ap);	</span><br><span class="line">	va_end(ap);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2-2-4-编写-my-vprintf-fmt-ap"><a href="#2-2-4-编写-my-vprintf-fmt-ap" class="headerlink" title="2.2.4 编写 my_vprintf(fmt, ap)  "></a><font size=3>2.2.4 编写 my_vprintf(fmt, ap)  </font></h4><p>参考 int vprintf(const char *format, va_list ap)实现 my_vprintf ，在my_printf.c中添加：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*reference :   int vprintf(const char *format, va_list ap); */</span></span><br><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">my_vprintf</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *fmt, va_list ap)</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">char</span> lead=<span class="string">&#x27; &#x27;</span>;</span><br><span class="line">	<span class="type">int</span>  maxwidth=<span class="number">0</span>;</span><br><span class="line">	</span><br><span class="line">	 <span class="keyword">for</span>(; *fmt != <span class="string">&#x27;\0&#x27;</span>; fmt++)		</span><br><span class="line">	 &#123;</span><br><span class="line">		<span class="keyword">if</span> (*fmt != <span class="string">&#x27;%&#x27;</span>) &#123;			</span><br><span class="line">			outc(*fmt);				</span><br><span class="line">			<span class="keyword">continue</span>;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		 lead=<span class="string">&#x27; &#x27;</span>;</span><br><span class="line">		 maxwidth=<span class="number">0</span>;</span><br><span class="line">		 </span><br><span class="line">		<span class="comment">//format : %08d, %8d,%d,%u,%x,%f,%c,%s </span></span><br><span class="line">		    fmt++;</span><br><span class="line">		<span class="keyword">if</span>(*fmt == <span class="string">&#x27;0&#x27;</span>)&#123;</span><br><span class="line">			lead = <span class="string">&#x27;0&#x27;</span>;</span><br><span class="line">			fmt++;	</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		</span><br><span class="line">		<span class="keyword">while</span>(*fmt &gt;= <span class="string">&#x27;0&#x27;</span> &amp;&amp; *fmt &lt;= <span class="string">&#x27;9&#x27;</span>)&#123;</span><br><span class="line">			maxwidth *=<span class="number">10</span>;</span><br><span class="line">			maxwidth += (*fmt - <span class="string">&#x27;0&#x27;</span>);</span><br><span class="line">			fmt++;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">switch</span> (*fmt) &#123;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;d&#x27;</span>: out_num(va_arg(ap, <span class="type">int</span>),          <span class="number">10</span>,lead,maxwidth); <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;o&#x27;</span>: out_num(va_arg(ap, <span class="type">unsigned</span> <span class="type">int</span>),  <span class="number">8</span>,lead,maxwidth); <span class="keyword">break</span>;				</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;u&#x27;</span>: out_num(va_arg(ap, <span class="type">unsigned</span> <span class="type">int</span>), <span class="number">10</span>,lead,maxwidth); <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;x&#x27;</span>: out_num(va_arg(ap, <span class="type">unsigned</span> <span class="type">int</span>), <span class="number">16</span>,lead,maxwidth); <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;c&#x27;</span>: outc(va_arg(ap, <span class="type">int</span>   )); <span class="keyword">break</span>;		</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;s&#x27;</span>: outs(va_arg(ap, <span class="type">char</span> *)); <span class="keyword">break</span>;		  		</span><br><span class="line">				</span><br><span class="line">		<span class="keyword">default</span>:  </span><br><span class="line">			outc(*fmt);</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2-2-5-编写-out-c，-outs-与-out-num-函数"><a href="#2-2-5-编写-out-c，-outs-与-out-num-函数" class="headerlink" title="2.2.5 编写 out_c， outs 与 out_num 函数  "></a><font size=3>2.2.5 编写 out_c， outs 与 out_num 函数  </font></h4><ul>
<li>（1）利用之前我们实现的单字节打印函数 void PutChar(int c)实现 out_c，outs 与 out_num 函数 outc 用于格式化输出中的%c 的输出。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">outc</span><span class="params">(<span class="type">int</span> c)</span> </span><br><span class="line">&#123;</span><br><span class="line">	PutChar(c);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>outs 用于格式化输出中的%s 的输出。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">outs</span> <span class="params">(<span class="type">const</span> <span class="type">char</span> *s)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">while</span> (*s != <span class="string">&#x27;\0&#x27;</span>)	</span><br><span class="line">		PutChar(*s++);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>out_num 用于格式化输出中的%d， %o， %u， %x 的输出。</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">out_num</span><span class="params">(<span class="type">long</span> n, <span class="type">int</span> base,<span class="type">char</span> lead,<span class="type">int</span> maxwidth)</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">unsigned</span> <span class="type">long</span> m=<span class="number">0</span>;</span><br><span class="line">	<span class="type">char</span> buf[MAX_NUMBER_BYTES], *s = buf + <span class="keyword">sizeof</span>(buf);</span><br><span class="line">	<span class="type">int</span> count=<span class="number">0</span>,i=<span class="number">0</span>;</span><br><span class="line">			</span><br><span class="line"></span><br><span class="line">	*--s = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span> (n &lt; <span class="number">0</span>)&#123;</span><br><span class="line">		m = -n;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span>&#123;</span><br><span class="line">		m = n;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">do</span>&#123;</span><br><span class="line">		*--s = hex_tab[m%base];</span><br><span class="line">		count++;</span><br><span class="line">	&#125;<span class="keyword">while</span> ((m /= base) != <span class="number">0</span>);</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span>( maxwidth &amp;&amp; count &lt; maxwidth)&#123;</span><br><span class="line">		<span class="keyword">for</span> (i=maxwidth - count; i; i--)	</span><br><span class="line">			*--s = lead;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">if</span> (n &lt; <span class="number">0</span>)</span><br><span class="line">		*--s = <span class="string">&#x27;-&#x27;</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">return</span> outs(s);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="2-2-6-测试函数"><a href="#2-2-6-测试函数" class="headerlink" title="2.2.6 测试函数"></a><font size=3>2.2.6 测试函数</font></h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">my_printf_test</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;This is www.100ask.org   my_printf test\n\r&quot;</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test char           =%c,%c\n\r&quot;</span>, <span class="string">&#x27;A&#x27;</span>,<span class="string">&#x27;a&#x27;</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test decimal number =%d\n\r&quot;</span>,    <span class="number">123456</span>) ;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test decimal number =%d\n\r&quot;</span>,    <span class="number">-123456</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test hex     number =0x%x\n\r&quot;</span>,  <span class="number">0x55aa55aa</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test string         =%s\n\r&quot;</span>,    <span class="string">&quot;www.100ask.org&quot;</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%08d\n\r&quot;</span>,   <span class="number">12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%8d\n\r&quot;</span>,    <span class="number">12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%08x\n\r&quot;</span>, <span class="number">0x12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%8x\n\r&quot;</span>,  <span class="number">0x12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%02x\n\r&quot;</span>, <span class="number">0x1</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%2x\n\r&quot;</span>,  <span class="number">0x1</span>);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%05d\n\r&quot;</span>, <span class="number">0x1</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%5d\n\r&quot;</span>,  <span class="number">0x1</span>);</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-3-移植后的工程结构"><a href="#2-3-移植后的工程结构" class="headerlink" title="2.3 移植后的工程结构"></a><font size=3>2.3 移植后的工程结构</font></h3><h4 id="2-3-1-目录结构"><a href="#2-3-1-目录结构" class="headerlink" title="2.3.1 目录结构"></a><font size=3>2.3.1 目录结构</font></h4><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240116233107762.png" alt="image-20240116233107762" style="zoom:50%;" />

<h4 id="2-3-2-imx6ull-lds"><a href="#2-3-2-imx6ull-lds" class="headerlink" title="2.3.2 imx6ull.lds"></a><font size=3>2.3.2 imx6ull.lds</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">SECTIONS &#123;</span><br><span class="line">    . = 0x80100000;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    .text      :</span><br><span class="line">    &#123;</span><br><span class="line">      *(.text)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    .rodata : &#123; *(.rodata) &#125;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    .data : &#123; *(.data) &#125;</span><br><span class="line"></span><br><span class="line">    . = ALIGN(4);</span><br><span class="line">    __bss_start = .;</span><br><span class="line">    .bss : &#123; *(.bss) *(.COMMON) &#125;</span><br><span class="line">    __bss_end = .;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-3-3-main-c"><a href="#2-3-3-main-c" class="headerlink" title="2.3.3 main.c"></a><font size=3>2.3.3 main.c</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;my_printf.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;uart.h&quot;</span></span></span><br><span class="line"><span class="type">int</span>  <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;	Uart_Init();</span><br><span class="line">	my_printf_test();			</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-3-4-start-S"><a href="#2-3-4-start-S" class="headerlink" title="2.3.4 start.S"></a><font size=3>2.3.4 start.S</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">.text</span><br><span class="line">.global  _start</span><br><span class="line">_start: 				</span><br><span class="line"></span><br><span class="line">	/* 设置栈 */</span><br><span class="line">	ldr  sp,=0x80200000</span><br><span class="line">	/* 清除bss段 */</span><br><span class="line">	bl clean_bss</span><br><span class="line">	/* 跳转到主函数 */</span><br><span class="line">	bl main</span><br><span class="line"></span><br><span class="line">halt:</span><br><span class="line">	b  halt </span><br><span class="line"></span><br><span class="line">clean_bss:</span><br><span class="line">	ldr r1, =__bss_start	// 将链接脚本变量__bss_start变量保存于r1</span><br><span class="line">	ldr r2, =__bss_end      // 将链接脚本变量__bss_end变量保存于r2</span><br><span class="line">	mov r3, #0</span><br><span class="line">clean:</span><br><span class="line">	strb r3, [r1]		// 将当前地址下的数据清零</span><br><span class="line">	add r1, r1, #1		// 将r1内存储的地址+1</span><br><span class="line">	cmp r1, r2		// 相等：清零操作结束；否则继续执行clean函数清零bss段</span><br><span class="line">	bne clean</span><br><span class="line">	</span><br><span class="line">	mov pc, lr</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-3-5-uart-c"><a href="#2-3-5-uart-c" class="headerlink" title="2.3.5 uart.c"></a><font size=3>2.3.5 uart.c</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;uart.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="type">static</span> <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA ;</span><br><span class="line"><span class="type">static</span> <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA	;</span><br><span class="line"><span class="type">static</span> <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *IOMUXC_UART1_RX_DATA_SELECT_INPUT ;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">Uart_Init</span><span class="params">(<span class="type">void</span>)</span>	 				</span><br><span class="line">&#123;</span><br><span class="line">	</span><br><span class="line">	IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA		= (<span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *)(<span class="number">0x20E0084</span>);</span><br><span class="line">	IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA		= (<span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *)(<span class="number">0x20E0088</span>);</span><br><span class="line">	IOMUXC_UART1_RX_DATA_SELECT_INPUT		= (<span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span> *)(<span class="number">0x20E0624</span>);</span><br><span class="line"></span><br><span class="line">	*IOMUXC_SW_MUX_CTL_PAD_UART1_RX_DATA = <span class="number">0</span>;</span><br><span class="line">	*IOMUXC_UART1_RX_DATA_SELECT_INPUT = <span class="number">3</span>;</span><br><span class="line">	*IOMUXC_SW_MUX_CTL_PAD_UART1_TX_DATA = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">	UART1-&gt;UCR1 |= (<span class="number">1</span> &lt;&lt; <span class="number">0</span>) ;		<span class="comment">/*关闭当前串口*/</span> </span><br><span class="line">	</span><br><span class="line">	<span class="comment">/* </span></span><br><span class="line"><span class="comment">	 *  设置UART传输格式：</span></span><br><span class="line"><span class="comment">	 *  UART1中的UCR2寄存器关键bit如下</span></span><br><span class="line"><span class="comment">	 *  [14]:	1：忽略RTS引脚</span></span><br><span class="line"><span class="comment">	 *  [8] :	0: 关闭奇偶校验 默认为0，无需设置</span></span><br><span class="line"><span class="comment">	 *  [6] :	0: 停止位1位	    默认为0，无需设置</span></span><br><span class="line"><span class="comment">	 *  [5] :	1: 数据长度8位</span></span><br><span class="line"><span class="comment">	 *  [2] :	1: 发送数据使能</span></span><br><span class="line"><span class="comment">	 *  [1] :	1: 接收数据使能</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	</span><br><span class="line">	UART1-&gt;UCR2 |= (<span class="number">1</span>&lt;&lt;<span class="number">14</span>) |(<span class="number">1</span>&lt;&lt;<span class="number">5</span>) |(<span class="number">1</span>&lt;&lt;<span class="number">2</span>)|(<span class="number">1</span>&lt;&lt;<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 *  UART1中的UCR3寄存器关键bit如下</span></span><br><span class="line"><span class="comment">	 *  [2]:  1:根据官方文档表示，IM6ULL的UART用了这个MUXED模型，提示要设置	</span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	</span><br><span class="line">	UART1-&gt;UCR3 |= (<span class="number">1</span>&lt;&lt;<span class="number">2</span>);</span><br><span class="line">	</span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">	 * 设置波特率</span></span><br><span class="line"><span class="comment">	 * 根据芯片手册得知波特率计算公式:</span></span><br><span class="line"><span class="comment">	 * Baud Rate = Ref Freq / (16 * (UBMR + 1)/(UBIR+1))</span></span><br><span class="line"><span class="comment">	 * 当我们需要设置 115200的波特率</span></span><br><span class="line"><span class="comment">	 * UART1_UFCR [9:7]=101，表示不分频，得到当前UART参考频率Ref Freq ：80M ，</span></span><br><span class="line"><span class="comment">	 * 带入公式：115200 = 80000000 /(16*(UBMR + 1)/(UBIR+1))</span></span><br><span class="line"><span class="comment">	 * </span></span><br><span class="line"><span class="comment">	 * 选取一组满足上式的参数：UBMR、UBIR即可</span></span><br><span class="line"><span class="comment">	 *	</span></span><br><span class="line"><span class="comment">	 * UART1_UBIR    = 71</span></span><br><span class="line"><span class="comment">	 * UART1_UBMR = 3124  </span></span><br><span class="line"><span class="comment">	 */</span></span><br><span class="line">	 </span><br><span class="line">    UART1-&gt;UFCR = <span class="number">5</span> &lt;&lt; <span class="number">7</span>;       <span class="comment">/* Uart的时钟clk：80MHz */</span></span><br><span class="line">    UART1-&gt;UBIR = <span class="number">71</span>;</span><br><span class="line">    UART1-&gt;UBMR = <span class="number">3124</span>;</span><br><span class="line"></span><br><span class="line">	UART1-&gt;UCR1 |= (<span class="number">1</span> &lt;&lt; <span class="number">0</span>);		<span class="comment">/*使能当前串口*/</span> </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">PutChar</span><span class="params">(<span class="type">int</span> c)</span>						</span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">while</span> (!((UART1-&gt;USR2) &amp; (<span class="number">1</span>&lt;&lt;<span class="number">3</span>))); <span class="comment">/*等待上个字节发送完毕*/</span></span><br><span class="line">	UART1-&gt;UTXD = (<span class="type">unsigned</span> <span class="type">char</span>)c;		</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">unsigned</span> <span class="type">char</span> <span class="title function_">GetChar</span><span class="params">(<span class="type">void</span>)</span>						</span><br><span class="line">&#123;	</span><br><span class="line">	<span class="keyword">while</span> (!(UART1-&gt;USR2 &amp; (<span class="number">1</span>&lt;&lt;<span class="number">0</span>)));  <span class="comment">/*等待接收数据*/</span></span><br><span class="line">	<span class="keyword">return</span> (<span class="type">unsigned</span> <span class="type">char</span>)UART1-&gt;URXD;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">PutStr</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *s)</span>				</span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">while</span> (*s)</span><br><span class="line">	&#123;</span><br><span class="line">		PutChar(*s);</span><br><span class="line">		s++;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">int</span> <span class="title function_">raise</span><span class="params">(<span class="type">int</span> signum)</span><span class="comment">/* raise函数，防止编译报错 */</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line">		  			 		  						  					  				 	   		  	  	 	  </span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-3-6-uart-h"><a href="#2-3-6-uart-h" class="headerlink" title="2.3.6 uart.h"></a><font size=3>2.3.6 uart.h</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">ifndef</span> _UART_H_</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> _UART_H_</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">/*UART1的寄存器的基地址*/</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> UART1_BASE          (0x2020000u)</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> UART1    ((UART_Type *)UART1_BASE)</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/*根据IMX6ULL芯片手册&lt;&lt;55.15 UART Memory Map/Register Definition&gt;&gt;的3608页，定义UART的结构体,*/</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> &#123;</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  URXD;               <span class="comment">/**&lt; UART Receiver Register, offset: 0x0 	           串口接收寄存器，偏移地址0x0     */</span></span><br><span class="line">  		   <span class="type">unsigned</span> <span class="type">char</span> RESERVED_0[<span class="number">60</span>];		</span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UTXD;               <span class="comment">/**&lt; UART Transmitter Register, offset: 0x40          串口发送寄存器，偏移地址0x40*/</span></span><br><span class="line">  		   <span class="type">unsigned</span> <span class="type">char</span> RESERVED_1[<span class="number">60</span>];		</span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR1;               <span class="comment">/**&lt; UART Control Register 1, offset: 0x80 	       串口控制寄存器1，偏移地址0x80*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR2;               <span class="comment">/**&lt; UART Control Register 2, offset: 0x84 	       串口控制寄存器2，偏移地址0x84*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR3;               <span class="comment">/**&lt; UART Control Register 3, offset: 0x88            串口控制寄存器3，偏移地址0x88*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UCR4;               <span class="comment">/**&lt; UART Control Register 4, offset: 0x8C            串口控制寄存器4，偏移地址0x8C*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UFCR;               <span class="comment">/**&lt; UART FIFO Control Register, offset: 0x90         串口FIFO控制寄存器，偏移地址0x90*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  USR1;               <span class="comment">/**&lt; UART Status Register 1, offset: 0x94             串口状态寄存器1，偏移地址0x94*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  USR2;               <span class="comment">/**&lt; UART Status Register 2, offset: 0x98             串口状态寄存器2，偏移地址0x98*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UESC;               <span class="comment">/**&lt; UART Escape Character Register, offset: 0x9C     串口转义字符寄存器，偏移地址0x9C*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UTIM;               <span class="comment">/**&lt; UART Escape Timer Register, offset: 0xA0         串口转义定时器寄存器 偏移地址0xA0*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UBIR;               <span class="comment">/**&lt; UART BRM Incremental Register, offset: 0xA4      串口二进制倍率增加寄存器 偏移地址0xA4*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UBMR;               <span class="comment">/**&lt; UART BRM Modulator Register, offset: 0xA8 	   串口二进制倍率调节寄存器 偏移地址0xA8*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UBRC;               <span class="comment">/**&lt; UART Baud Rate Count Register, offset: 0xAC      串口波特率计数寄存器 偏移地址0xAC*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  ONEMS;              <span class="comment">/**&lt; UART One Millisecond Register, offset: 0xB0      串口一毫秒寄存器 偏移地址0xB0*/</span></span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UTS;                <span class="comment">/**&lt; UART Test Register, offset: 0xB4                 串口测试寄存器 偏移地址0xB4*/</span>		</span><br><span class="line">  <span class="keyword">volatile</span> <span class="type">unsigned</span> <span class="type">int</span>  UMCR;               <span class="comment">/**&lt; UART RS-485 Mode Control Register, offset: 0xB8  串口485模式控制寄存器 偏移地址0xB8*/</span></span><br><span class="line">&#125; UART_Type;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">Uart_Init</span><span class="params">(<span class="type">void</span>)</span>;		</span><br><span class="line"><span class="type">void</span> <span class="title function_">PutChar</span><span class="params">(<span class="type">int</span> c)</span>;</span><br><span class="line"></span><br><span class="line"> <span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">		  			 		  						  					  				 	   		  	  	 	  </span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-3-7-Makefile"><a href="#2-3-7-Makefile" class="headerlink" title="2.3.7 Makefile"></a><font size=3>2.3.7 Makefile</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">PREFIX=arm-linux-gnueabihf-</span><br><span class="line">CC=<span class="variable">$(PREFIX)</span>gcc</span><br><span class="line">LD=<span class="variable">$(PREFIX)</span>ld</span><br><span class="line">AR=<span class="variable">$(PREFIX)</span>ar</span><br><span class="line">OBJCOPY=<span class="variable">$(PREFIX)</span>objcopy</span><br><span class="line">OBJDUMP=<span class="variable">$(PREFIX)</span>objdump</span><br><span class="line"></span><br><span class="line">my_printf.img : start.S  uart.c main.c my_printf.c</span><br><span class="line">	<span class="variable">$(CC)</span> -nostdlib -g -c -o start.o start.S </span><br><span class="line">	<span class="variable">$(CC)</span> -nostdlib -g -c -o uart.o uart.c	</span><br><span class="line">	<span class="variable">$(CC)</span> -nostdlib -g -c -o main.o main.c	</span><br><span class="line">	<span class="variable">$(CC)</span> -nostdlib -g -c -o my_printf.o my_printf.c</span><br><span class="line">	</span><br><span class="line">	<span class="variable">$(LD)</span> -T imx6ull.lds -g start.o uart.o main.o my_printf.o -o my_printf.elf -lgcc -L/home/book/100ask_imx6ull-sdk/ToolChain/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/lib/gcc/arm-linux-gnueabihf/6.2.1</span><br><span class="line">	</span><br><span class="line">	<span class="variable">$(OBJCOPY)</span> -O binary -S my_printf.elf  my_printf.bin</span><br><span class="line">	<span class="variable">$(OBJDUMP)</span> -D -m arm  my_printf.elf  &gt; my_printf.dis	</span><br><span class="line">	./tools/mkimage -n ./tools/imximage.cfg.cfgtmp -T imximage -e 0x80100000 -d my_printf.bin my_printf.imx</span><br><span class="line">	dd if=/dev/zero of=1k.bin bs=1024 count=1</span><br><span class="line">	cat 1k.bin my_printf.imx &gt; my_printf.img</span><br><span class="line"></span><br><span class="line"><span class="section">clean:</span></span><br><span class="line">	rm -f my_printf.dis  my_printf.bin my_printf.elf my_printf.imx my_printf.img *.o</span><br><span class="line"></span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-3-8-mp-printf-c"><a href="#2-3-8-mp-printf-c" class="headerlink" title="2.3.8 mp_printf.c"></a><font size=3>2.3.8 mp_printf.c</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span>  <span class="string">&quot;my_printf.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span>  <span class="string">&quot;uart.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//==================================================================================================</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="type">char</span> *  va_list;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> _INTSIZEOF(n)   ( (sizeof(n) + sizeof(int) - 1) &amp; ~(sizeof(int) - 1) )</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> va_start(ap,v)  ( ap = (va_list)&amp;v + _INTSIZEOF(v) )</span></span><br><span class="line"><span class="comment">//#define va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> va_arg(ap,t)    ( *(t *)( ap=ap + _INTSIZEOF(t), ap- _INTSIZEOF(t)) )</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> va_end(ap)      ( ap = (va_list)0 )</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//==================================================================================================</span></span><br><span class="line">		  			 		  						  					  				 	   		  	  	 	  </span><br><span class="line"><span class="type">unsigned</span> <span class="type">char</span> hex_tab[]=&#123;<span class="string">&#x27;0&#x27;</span>,<span class="string">&#x27;1&#x27;</span>,<span class="string">&#x27;2&#x27;</span>,<span class="string">&#x27;3&#x27;</span>,<span class="string">&#x27;4&#x27;</span>,<span class="string">&#x27;5&#x27;</span>,<span class="string">&#x27;6&#x27;</span>,<span class="string">&#x27;7&#x27;</span>,\</span><br><span class="line">		                 <span class="string">&#x27;8&#x27;</span>,<span class="string">&#x27;9&#x27;</span>,<span class="string">&#x27;a&#x27;</span>,<span class="string">&#x27;b&#x27;</span>,<span class="string">&#x27;c&#x27;</span>,<span class="string">&#x27;d&#x27;</span>,<span class="string">&#x27;e&#x27;</span>,<span class="string">&#x27;f&#x27;</span>&#125;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">outc</span><span class="params">(<span class="type">int</span> c)</span> </span><br><span class="line">&#123;</span><br><span class="line">	PutChar(c);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">outs</span> <span class="params">(<span class="type">const</span> <span class="type">char</span> *s)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="keyword">while</span> (*s != <span class="string">&#x27;\0&#x27;</span>)	</span><br><span class="line">		PutChar(*s++);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">out_num</span><span class="params">(<span class="type">long</span> n, <span class="type">int</span> base,<span class="type">char</span> lead,<span class="type">int</span> maxwidth)</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">unsigned</span> <span class="type">long</span> m=<span class="number">0</span>;</span><br><span class="line">	<span class="type">char</span> buf[MAX_NUMBER_BYTES], *s = buf + <span class="keyword">sizeof</span>(buf);</span><br><span class="line">	<span class="type">int</span> count=<span class="number">0</span>,i=<span class="number">0</span>;</span><br><span class="line">			</span><br><span class="line"></span><br><span class="line">	*--s = <span class="string">&#x27;\0&#x27;</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span> (n &lt; <span class="number">0</span>)&#123;</span><br><span class="line">		m = -n;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">else</span>&#123;</span><br><span class="line">		m = n;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">do</span>&#123;</span><br><span class="line">		*--s = hex_tab[m%base];</span><br><span class="line">		count++;</span><br><span class="line">	&#125;<span class="keyword">while</span> ((m /= base) != <span class="number">0</span>);</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span>( maxwidth &amp;&amp; count &lt; maxwidth)&#123;</span><br><span class="line">		<span class="keyword">for</span> (i=maxwidth - count; i; i--)	</span><br><span class="line">			*--s = lead;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">if</span> (n &lt; <span class="number">0</span>)</span><br><span class="line">		*--s = <span class="string">&#x27;-&#x27;</span>;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">return</span> outs(s);</span><br><span class="line">&#125;</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="comment">/*reference :   int vprintf(const char *format, va_list ap); */</span></span><br><span class="line"><span class="type">static</span> <span class="type">int</span> <span class="title function_">my_vprintf</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *fmt, va_list ap)</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">char</span> lead=<span class="string">&#x27; &#x27;</span>;</span><br><span class="line">	<span class="type">int</span>  maxwidth=<span class="number">0</span>;</span><br><span class="line">	</span><br><span class="line">	 <span class="keyword">for</span>(; *fmt != <span class="string">&#x27;\0&#x27;</span>; fmt++)		</span><br><span class="line">	 &#123;</span><br><span class="line">		<span class="keyword">if</span> (*fmt != <span class="string">&#x27;%&#x27;</span>) &#123;			</span><br><span class="line">			outc(*fmt);				</span><br><span class="line">			<span class="keyword">continue</span>;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		 lead=<span class="string">&#x27; &#x27;</span>;</span><br><span class="line">		 maxwidth=<span class="number">0</span>;</span><br><span class="line">		 </span><br><span class="line">		<span class="comment">//format : %08d, %8d,%d,%u,%x,%f,%c,%s </span></span><br><span class="line">		    fmt++;</span><br><span class="line">		<span class="keyword">if</span>(*fmt == <span class="string">&#x27;0&#x27;</span>)&#123;</span><br><span class="line">			lead = <span class="string">&#x27;0&#x27;</span>;</span><br><span class="line">			fmt++;	</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		</span><br><span class="line">		<span class="keyword">while</span>(*fmt &gt;= <span class="string">&#x27;0&#x27;</span> &amp;&amp; *fmt &lt;= <span class="string">&#x27;9&#x27;</span>)&#123;</span><br><span class="line">			maxwidth *=<span class="number">10</span>;</span><br><span class="line">			maxwidth += (*fmt - <span class="string">&#x27;0&#x27;</span>);</span><br><span class="line">			fmt++;</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		<span class="keyword">switch</span> (*fmt) &#123;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;d&#x27;</span>: out_num(va_arg(ap, <span class="type">int</span>),          <span class="number">10</span>,lead,maxwidth); <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;o&#x27;</span>: out_num(va_arg(ap, <span class="type">unsigned</span> <span class="type">int</span>),  <span class="number">8</span>,lead,maxwidth); <span class="keyword">break</span>;				</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;u&#x27;</span>: out_num(va_arg(ap, <span class="type">unsigned</span> <span class="type">int</span>), <span class="number">10</span>,lead,maxwidth); <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;x&#x27;</span>: out_num(va_arg(ap, <span class="type">unsigned</span> <span class="type">int</span>), <span class="number">16</span>,lead,maxwidth); <span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;c&#x27;</span>: outc(va_arg(ap, <span class="type">int</span>   )); <span class="keyword">break</span>;		</span><br><span class="line">		<span class="keyword">case</span> <span class="string">&#x27;s&#x27;</span>: outs(va_arg(ap, <span class="type">char</span> *)); <span class="keyword">break</span>;		  		</span><br><span class="line">				</span><br><span class="line">		<span class="keyword">default</span>:  </span><br><span class="line">			outc(*fmt);</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//reference :  int printf(const char *format, ...); </span></span><br><span class="line"><span class="type">int</span> <span class="title function_">printf</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *fmt, ...)</span> </span><br><span class="line">&#123;</span><br><span class="line">	va_list ap;</span><br><span class="line"></span><br><span class="line">	va_start(ap, fmt);</span><br><span class="line">	my_vprintf(fmt, ap);	</span><br><span class="line">	va_end(ap);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">my_printf_test</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;This is www.100ask.org   my_printf test\n\r&quot;</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test char           =%c,%c\n\r&quot;</span>, <span class="string">&#x27;A&#x27;</span>,<span class="string">&#x27;a&#x27;</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test decimal number =%d\n\r&quot;</span>,    <span class="number">123456</span>) ;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test decimal number =%d\n\r&quot;</span>,    <span class="number">-123456</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test hex     number =0x%x\n\r&quot;</span>,  <span class="number">0x55aa55aa</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;test string         =%s\n\r&quot;</span>,    <span class="string">&quot;www.100ask.org&quot;</span>) ;	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%08d\n\r&quot;</span>,   <span class="number">12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%8d\n\r&quot;</span>,    <span class="number">12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%08x\n\r&quot;</span>, <span class="number">0x12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%8x\n\r&quot;</span>,  <span class="number">0x12345</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%02x\n\r&quot;</span>, <span class="number">0x1</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=0x%2x\n\r&quot;</span>,  <span class="number">0x1</span>);</span><br><span class="line"></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%05d\n\r&quot;</span>, <span class="number">0x1</span>);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;num=%5d\n\r&quot;</span>,  <span class="number">0x1</span>);</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h4 id="2-3-9-my-printf-h"><a href="#2-3-9-my-printf-h" class="headerlink" title="2.3.9 my_printf.h"></a><font size=3>2.3.9 my_printf.h</font></h4><details class="folding-tag" blue><summary> 点击查看详情 </summary>
              <div class='content'>
              <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">ifndef</span> _MY_PRINTF_H</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> _MY_PRINTF_H</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span>  MAX_NUMBER_BYTES  	64</span></span><br><span class="line"><span class="keyword">extern</span> <span class="type">int</span> <span class="title function_">my_printf_test</span><span class="params">(<span class="type">void</span>)</span>;</span><br><span class="line"><span class="type">int</span> <span class="title function_">printf</span><span class="params">(<span class="type">const</span> <span class="type">char</span> *fmt, ...)</span>;</span><br><span class="line">		  			 		  						  					  				 	   		  	  	 	  </span><br><span class="line"><span class="meta">#<span class="keyword">endif</span> <span class="comment">/* _MY_PRINTF_H */</span></span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h3 id="2-4-测试效果"><a href="#2-4-测试效果" class="headerlink" title="2.4 测试效果"></a><font size=3>2.4 测试效果</font></h3><p>不出意外，一切顺利的话我们应该会得到以下输出：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">This is www.100ask.org my_printf test</span><br><span class="line">test char =A,a</span><br><span class="line">test decimal number =123456</span><br><span class="line">test decimal number =-123456</span><br><span class="line">test hex number =0x55aa55aa</span><br><span class="line">test string =www.100ask.org</span><br><span class="line">num=00012345</span><br><span class="line">num= 12345</span><br><span class="line">num=0x00012345</span><br><span class="line">num=0x 12345</span><br><span class="line">num=0x01</span><br><span class="line">num=0x 1</span><br><span class="line">num=00001</span><br><span class="line">num= 1</span><br></pre></td></tr></table></figure>

<p>串口终端如果打印以上信息，证明实验成功！  </p>
<h2 id="2-5-地址打印"><a href="#2-5-地址打印" class="headerlink" title="2.5 地址打印"></a><font size=3>2.5 地址打印</font></h2><p>我们来看一下上面移植好后，对地址的打印情况：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;my_printf.h&quot;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&quot;uart.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="type">char</span> g_charA = <span class="string">&#x27;A&#x27;</span>;       <span class="comment">// 存储在 .data 段</span></span><br><span class="line"><span class="type">const</span> <span class="type">char</span> g_charB = <span class="string">&#x27;B&#x27;</span>; <span class="comment">// 存储在 .rodata 段</span></span><br><span class="line"><span class="type">const</span> <span class="type">char</span> g_charC; <span class="comment">// 存储在 .bss 段</span></span><br><span class="line"><span class="type">int</span> g_intA = <span class="number">0</span>;     <span class="comment">// 存储在 .bss 段</span></span><br><span class="line"><span class="type">int</span> g_intB;         <span class="comment">// 存储在 .bss 段</span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">const</span> <span class="type">char</span> * argv[])</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">int</span> c = <span class="number">9</span>;</span><br><span class="line"> 	Uart_Init();</span><br><span class="line">	my_printf_test();	</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;\n\r&quot;</span>);<span class="comment">//反过来会报错，具体原因未知，还没有深究</span></span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;g_charA=%d &amp;g_charA=0x%x\n\r&quot;</span>, g_charA, &amp;g_charA);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;g_charB=%d &amp;g_charB=0x%x\n\r&quot;</span>, g_charB, &amp;g_charB);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;g_charC=%d &amp;g_intA=0x%x\n\r&quot;</span>, g_charC, &amp;g_charC);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;g_intA=%d &amp;g_intA=0x%x\n\r&quot;</span>, g_intA, &amp;g_intA);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;g_intB=%d &amp;g_intB=0x%x\n\r&quot;</span>, g_intB, &amp;g_intB);</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;c=%d &amp;c=0x%x\n\r&quot;</span>, c, &amp;c);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>不出意外的话，我们会得到以下打印输出：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240119003227288.png" alt="image-20240119003227288" />

<p>会发现全是错的，具体原因可能还是哪里移植的不太对，后面进行了修改，修改后的工程可以直接看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-bare-demo/tree/master/02_UART/04_my_printf">imx6ull-bare-demo: imx6ull的裸机开发demo - Gitee.com</a>。修改完后打印信息如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-04-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1-03-%E4%B8%B2%E5%8F%A3%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%87%BD%E6%95%B0%E7%A7%BB%E6%A4%8D/img/image-20240119003653270.png" alt="image-20240119003653270" />

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/9f4500db.html">LV04-04-串口通信-03-串口格式化函数移植</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年09月08日 - 19:24</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/9f4500db.html" title="LV04-04-串口通信-03-串口格式化函数移植">https://sumumm.github.io/post/9f4500db.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/ALPHA-LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> (ALPHA)LV04-裸机开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/f1aead6d.html" rel="prev" title="LV02-01-交叉编译工具链">
                  <i class="fa fa-angle-left"></i> LV02-01-交叉编译工具链
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/28f07778.html" rel="next" title="LV04-04-串口通信-02-IMX6ULL的UART配置">
                  LV04-04-串口通信-02-IMX6ULL的UART配置 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
